package com.example.demo.ui.dashboard;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.demo.MyAdapterTest;
import com.example.demo.R;
import com.example.demo.TheItems;

import java.util.ArrayList;
import java.util.List;

public class DashboardFragment extends Fragment {
    private Context context;
    private List<TheItems> apps = new ArrayList<TheItems>();
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        RecyclerView recycleView2 = view.findViewById(R.id.recycle_view2);

        context = getContext();

        //1.指定表现形式
        //列表
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);

        //网格  这两种常用
        //GridLayoutManager gridLayoutManager = new GridLayoutManager(context,2);

        //指定形式
        recycleView2.setLayoutManager(linearLayoutManager);

        //2.自定义适配器
        MyAdapterTest myAdapterTest = new MyAdapterTest();
        recycleView2.setAdapter(myAdapterTest);

        //3.设置数据
        initData();
        //myAdapterTest.setData(apps);


    }

    public void initData(){

        TheItems theItems = new TheItems();
        theItems.setTvRank("1");
        theItems.setImg(R.drawable.touxiang);
        theItems.setTvName("QQ");
        theItems.setTvStart("999次");
        theItems.setTvDowloadCount("999999");
        theItems.setButton2("更新");
        apps.add(theItems);



        TheItems theItems1 = new TheItems();
        theItems1.setTvRank("2");
        theItems1.setImg(R.drawable.booko);
        theItems1.setTvName("微信");
        theItems1.setTvStart("999次");
        theItems1.setTvDowloadCount("999999");
        theItems1.setButton2("更新");
        apps.add(theItems1);



        TheItems theItems2 = new TheItems();
        theItems2.setTvRank("3");
        theItems2.setImg(R.drawable.booko);
        theItems2.setTvName("微信");
        theItems2.setTvStart("999555次");
        theItems2.setTvDowloadCount("55555");
        theItems2.setButton2("更新");
        apps.add(theItems2);


        TheItems theItems3 = new TheItems();
        theItems3.setTvRank("4");
        theItems3.setImg(R.mipmap.circle);
        theItems3.setTvName("微信");
        theItems3.setTvStart("999次");
        theItems3.setTvDowloadCount("999999");
        theItems3.setButton2("更新");
        apps.add(theItems3);
    }

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_dashboard, container, false);

        return root;
    }
}